﻿using System;
using System.Collections;
using Gp.Scripts.Core;
using Gp.Scripts.Data;
using Gp.Scripts.Equip;
using Gp.Scripts.GUI;
using UnityEngine;

namespace Gp.Scripts.Core {
    /// <summary>
    /// 由 格挡行为 引起的反应 的参数
    /// </summary>
    public class DodgeAttackReactionArgs : ReactionArgs{
        public readonly AttackPreReaction AttackPreReaction;

        
        public DodgeAttackReactionArgs(AttackPreReaction attackPreReaction) {
            AttackPreReaction = attackPreReaction;
        }
    }
    
    
    
    /// <summary>
    /// 触发 格挡反应 的处理。在单位进行格挡后，还会触发链式反应
    /// </summary>
    public class DodgeAttackReactionWrapper : ReactionRegister<AttackPreReaction> {
        public DodgeAttackReactionWrapper(BaseUnit unit) : base(unit) { }
        private const int ResourceCost = 1;

        protected override bool CanPerform(AttackPreReaction e) {
            return e.Target == Unit 
                 && CheckResource(e)
                 ;
        }

        private Vector3 _clickPos;
        protected override IEnumerator OnSelect(AttackPreReaction arg) {
            bool blocked = true;
            throw new NotImplementedException("Not yet implemented");
            // Global.Get<GridBattleGUISystem>().GetIndicator<UnitSkillIndicator>().Display(Unit, clickPos => {
            //     _clickPos = clickPos;
            //     blocked = false;
            // });
            // while (blocked) yield return null;
        }


        protected override void OnRender(AttackPreReaction e, ReactionRenderInfo info) {
            // info.Icon = e.Target.Avatar;
            info.Title = "闪避";
        }
        
        
        

        protected override IEnumerator OnTrigger(AttackPreReaction args) {
            // yield return Unit.ComSkill.MoveSkill.(_clickPos);
            yield break;
        }


        private bool CheckResource(AttackPreReaction e) {
            // 有防御点（反应） 或“格挡”buff
            return e.Target.ComCost.CheckResource(CostField.Reaction, ResourceCost);
        }
    }
}